let routerMethods = {
    components: {},
    data() {
        return {}
    },
    computed: {
        _apiList() {
            return this.$store.getters.getApiList
        }
    },
    mounted() {
    },
    methods: {
        /**
         * 调用接口
         * @param api
         * @param data
         * @returns {Promise<any>}
         */
        callApi(api, data) {
            let apiItem = this._apiList.find(item => {
                return item.key === api
            })
            if (!apiItem) {
                this.$message.error("访问错误，接口不存在或无访问权限！")
                console.log("接口不存在或无访问权限！" + api);
                return new Promise(((resolve, reject) => {
                    reject()
                }))
            }

            let result = null
            switch (apiItem.method) {
                case "post":
                    result = this.$api.$post(apiItem.path, data)
                    break
                case "get":
                    result = this.$api.$get(apiItem.path, data)
                    break
                case "upload":
                    result = this.$api.$upload(apiItem.path, data)
                    break
                case "download":
                    result = this.$api.$download(apiItem.path, data)
                    break
            }
            return result
        }
    },
    watch: {}
}
export default routerMethods
